/**
 * 
 */
package com.chocolatefordogs.writersnb.app.notes;

import java.util.List;
import java.util.ResourceBundle;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.MutableTreeNode;

import com.chocolatefordogs.writersnb.app.treeutils.TreeNodeBuilder;
import com.chocolatefordogs.writersnb.core.NotedObject;
import com.chocolatefordogs.writersnb.notes.Note;
import com.chocolateforogs.writersnb.res.ResourceLoader;

/**
 * @author Matthew
 *
 */
public final class NotedObjectNodeBuilder implements TreeNodeBuilder<NotedObject> {
	
	private NotedObjectNodeBuilder() { }

	@Override
	public MutableTreeNode buildNode(final NotedObject item) {
		MutableTreeNode res = new DefaultMutableTreeNode(resources.getString("notes.title"));
		if (item.hasNotes()) {
			final List<Note> notes = item.getNotes();
			for (final Note n : notes) {
				res.insert(nnb.buildNode(n), res.getChildCount());
			}
		}
		return res;
	}
	
	public static TreeNodeBuilder<NotedObject> getInstance() {
		return instance;
	}
	
	private final ResourceBundle resources = ResourceLoader.getClassResources(getClass());

	private static final NotedObjectNodeBuilder instance = new NotedObjectNodeBuilder();
	private static final TreeNodeBuilder<Note> nnb = NoteNodeBuilder.getInstance();
}
